package reduce.fz.com.reduce.fragment;


import android.app.Dialog;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.TypeReference;

import java.util.HashMap;

import de.greenrobot.event.EventBus;
import reduce.fz.com.reduce.R;
import reduce.fz.com.reduce.abstracts.AbResponseListener;
import reduce.fz.com.reduce.bean.ServiceException;
import reduce.fz.com.reduce.bean.StoryReply;
import reduce.fz.com.reduce.bean.Team;
import reduce.fz.com.reduce.bean.TeamSubject;
import reduce.fz.com.reduce.bean.User;
import reduce.fz.com.reduce.bean.result.Result;
import reduce.fz.com.reduce.custom.LoadingDialog;
import reduce.fz.com.reduce.event.PubSubjectEvent;
import reduce.fz.com.reduce.fragment.base.BaseFragment;
import reduce.fz.com.reduce.service.TeamService;
import reduce.fz.com.reduce.service.preference.UserPreference;
import reduce.fz.com.reduce.util.InputMethodUtil;
import reduce.fz.com.reduce.util.ServiceBuilder;

/**
 *小组话题发表页面
 */
public class TeamSubjectFragment extends BaseViewPagerFragment  {

    private Team team;
    private FrameLayout subjectListContainer;
    private TeamService teamService= ServiceBuilder.builderTeamService(null);

    private TeamSubjectListFragment subjectListFragment;

    public void initWidget(View view)
    {
    }

    public void attachTeamSubjectListFragment() {

        subjectListFragment = TeamSubjectListFragment.create(team.teamid);
        getChildFragmentManager().beginTransaction().replace(R.id.subject_list_container, subjectListFragment).commit();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        team = (Team) getArguments().getSerializable("team");
        EventBus.getDefault().register(this);

    }

    public void onEvent(PubSubjectEvent event)
    {
        subjectListFragment.addFrist(event.subject);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }







    public static TeamSubjectFragment create(Team team,int position) {
        TeamSubjectFragment fragment = new TeamSubjectFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("team", team);
        bundle.putInt(BUNDLE_FRAGMENT_INDEX,position);
        fragment.setArguments(bundle);
        return fragment;

    }


    public TeamSubjectFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view= inflater.inflate(R.layout.fragment_team_subject, container, false);
        initWidget(view);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        attachTeamSubjectListFragment();
    }









    @Override
    public boolean isViewBeingDragged(MotionEvent event) {
        return subjectListFragment.isViewBeingDragged(event);
    }
}
